package org.clockwise.nlpir;

import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;

public class ResultParser {
	
	public static String[][] parse(String line) {
		line = line.trim();
		String[][] result = new String[2][];
		String[] segment = line.split(" ");
		result[0] = new String[segment.length];
		result[1] = new String[segment.length];
		for (int i = segment.length - 1; i >= 0; i--) {
			String[] pair = segment[i].split("/");
			if (pair.length == 2) {
				result[0][i] = pair[0];
				result[1][i] = pair[1];
			}
			else {
				result[0][i] = "";
				result[1][i] = "";
			}
		}
		return result;
	}
	
	public static List<List<String>> parseWords(String line) {
		List<String> words = new ArrayList<String>();
		List<String> labels = new ArrayList<String>();
		
		String[] segment = line.split(" ");
		int size = segment.length;
		for (int i = 0; i < size; i++) {
			if (segment[i].length() > 2) {
				String[] pair = segment[i].split("/");
				if (pair.length == 2) {
					words.add(pair[0]);
					labels.add(pair[1]);
				}
			}
		}
		List<List<String>> list = new ArrayList<List<String>>();
		list.add(words);
		list.add(labels);
		return list;
	}
	
	public static void printLine(String line) {
		String[] segment = line.split(" ");
		for (int i = 0; i < segment.length; i++) {
			System.out.print("\"" + segment[i] + "\" ");
		}
		System.out.println("");
	}
	
	public static void printSegment(String[] segment) {
		for (int i = 0; i < segment.length; i++) {
			System.out.print("\"" + segment[i] + "\" ");
		}
		System.out.println("");
	}
	
}
